import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import Controls from '#cpt/temp/Controls'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 					= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 				= $Lazy.file(()=>import('#private/cache-api'))
const $time 				= $Lazy.file(()=>import('@com/utils/time'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 搜索表单列表
		forms : [
			{ label: '医院',		name: 'hosp_id',				type: 'select', loading:true },
			{ label: '统计时间',		names: ['start_at','end_at'],	name:'jz-time', type:'date-range' },
			{ label: '科室',		name: 'project_parent_id',		type: 'select', loading:true, idStr:'uuid' },
			{ label: '岗位',		name: 'project_id',				type: 'select', loading:true },
		]
	}
	
	model = {}
	
	componentDidMount(){
		this.getSelect()
		/* 添加默认时间为一周 2021-08-23  --耿琰 */
		// 设置时间默认值
		$time.then(f=>{
			const arr = f.duration['7']()
			this.resetModel = { start_at: arr[0], end_at: arr[1], 'jz-time':arr }
			this.model = $fn.copy(this.resetModel)
			if(window.isInit){
				this.fetch()
			}
		})
	}
	//获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 医院
			$fn.setRow( forms, 'hosp_id', await f.getCache({ api:'hospital' }) )
			// 科室
			$fn.setRow(forms, 'project_parent_id', await f.getCache({ api:'ke_shi' } ) )
			// 岗位
			$fn.setRow(forms, 'project_id', await f.getCache({ api:'gang_wei' } ) )
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'statistics/labSpecimenCount',{ callback: ({current_page_total})=> this.setState({current_page_total})})
	
	// 表单
	cols = [
		{ title: '医院', 		dataIndex: 'hosp_name', 				width:100 },
		{ title: '开始时间', 	dataIndex: 'start_at', 					width:100 },
		{ title: '结束时间', 	dataIndex: 'end_at', 					width:150 },
		{ title: '科室', 		dataIndex: 'project_parent_name', 		width:150 },
		{ title: '岗位', 		dataIndex: 'project_name', 				width:150 },
		/* 标本量字段增加排序 2021-08-23  --耿琰 */
		{ title: '标本量', 		dataIndex: 'count_total', 				...$fn.table.num, sorter:true },
	]
	
	// 操作按钮
	controls = () => {
		return [
			Controls.exports.call(this, 'statistics/labSpecimenCount'),			// 导出
		]
	}
	
	render(){
		const { current_page_total } = this.state
		return (
			<>
				<Page title='实验室标本量' controls={this.controls()}>
					{/* 搜索 */}
					{ SearchForm.call(this,{ timeStr:'7' }) }
					{/* 表格 */}
					{ Table.call(this,
						{sort:true, isInit:window.isInit, suffix: (
							<>
								<div className='ml10 g9'>当页总标本量 <b className='f14 c0'>{current_page_total||0}</b>
									<span className='ml10' style={{color:'red'}}>在当前统计下，同主条码、同岗位、同标本类型的标本按同一个标本统计</span>
								</div>
							</>
						)
						}) 
					}
				</Page>
			</>
		)
	}
}

export default Index